﻿using LF.Domain.Entities;
using LF.Domain.Helper;
using LF.Domain.Services;
using LF.Domain.Services.Iml;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.Modularity;
using LF.Common;
using LF.Domain.Seed;
using Microsoft.Extensions.Configuration;

namespace LF.Domain;
public class DomainModule : AbpModule
{
    public override void OnApplicationInitialization(ApplicationInitializationContext context)
    {
        var rule = FreeSqlHelper.DbContext.Queryable<Rule>().First();
        var dics = FreeSqlHelper.DbContext.Queryable<AppDic>().ToList();
        DomainConfig.Rule = new RuleConfig
        {
            Rule = rule
        };
        DomainConfig.AppDics = dics;
        // 初始化所有种子数据
        var seedDataInitializer = context.ServiceProvider.GetRequiredService<SystemSeedDataInitializer>();
        seedDataInitializer.Initialize();
    }
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        var services = context.Services;
        
                    // 配置域服务
          
            services.AddTransient<IMenuManagerService, MenuManagerService>();
            services.AddTransient<IDeptmentManagerService, DeptmentManagerService>();
            services.AddTransient<IUserManagerService, UserManagerService>();
            services.AddTransient<IRoleManagerService, RoleManagerService>();
        base.ConfigureServices(context);
        var config = context.Services.GetConfiguration().GetSection("db");
        //var qdrant = context.Services.GetConfiguration().GetSection("qdrant");
        //services.Configure<QdrantConfig>(qdrant);
        //DomainConfig.QdrantConfig = qdrant.Get<QdrantConfig>();
        DomainConfig.Connection = config["mysql"]!;
        DomainConfig.SqlXml = Path.Combine(AppConfig.BasePath, "Config", "sql.xml");
        DomainConfig.FilePath = context.Services.GetConfiguration().GetSection("file").GetSection("path").Value??"";
        services.AddSingleton<SystemSeedDataInitializer>();
    }
}

